package com.biz.primus.base.support.rest.controller;

import com.biz.primus.base.exception.BizException;
import com.biz.primus.base.exception.CommonExceptions;
import com.biz.primus.base.support.rest.vo.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author yanweijin
 * @date 2017/11/29
 */
public class BaseRestController {


	@ExceptionHandler(Exception.class)
	@ResponseBody
	protected JsonResult exceptionHandler(Exception ex){
		ex.printStackTrace();
		if(ex instanceof BizException){
			BizException bizException = (BizException)ex;
			return new JsonResult(bizException);
		}else if(ex instanceof IllegalArgumentException){
			return new JsonResult(CommonExceptions.PARAM_ERROR);
		}else{
			return new JsonResult(CommonExceptions.SERVER_ERROR);
		}
	}
}
